package main

import (
	"fmt"
	"go-study/面向伪对象/接口"
	"go-study/面向伪对象/接口/mock"
	"go-study/面向伪对象/接口/network"
)

func main() {
	mockFileDownload := mock.FileDownload{Content: "this is new content"}
	inspect(mockFileDownload)

	networkFileDownload := &network.FileDownload{Header: "header:header"}
	// fmt.Println(networkFileDownload.Download("https://www.baidu.com"))
	inspect(networkFileDownload)

	uploadDownload(mockFileDownload)
}

func uploadDownload(file 接口.FileUploadDownload) {
	file.Upload("http://www.baidu.com", map[string]int{
		"age": 26,
		"sex": 1,
	})
	file.Download("http://www.baidu.com")
	fmt.Println("file total size :", file.TotalFileSize())
}

/**
输出类型和部分内容
*/
func inspect(fileDownload 接口.FileDownload) {
	fmt.Printf("Type:[%T],Value:[%v]\n", fileDownload, fileDownload)
	switch download := fileDownload.(type) {
	case mock.FileDownload:
		fmt.Println("mock download:", download.Content)
	case *network.FileDownload:
		fmt.Println("network download", download.Header)
	default:
		fmt.Printf("出现未知的类型Type:[%T],Value:[%v]", fileDownload, fileDownload)
		panic("出现过未知的类型")
	}
}
